package config

import (
	"common/helper"
	"database/sql"
)

/*
vip配置
*/
type CfgVipItem struct {
	Level       int64   `json:"level" db:"level"`
	NeedRunning float64 `json:"needRunning" db:"needRunning"`
	UpBonus     float64 `json:"upBonus" db:"upBonus"`
	WeekBonus   float64 `json:"weekBonus" db:"weekBonus"`
	MonthBonus  float64 `json:"monthBonus" db:"monthBonus"`
}

var cfgVipList []CfgVipItem

func GetVipCfg() []CfgVipItem {
	return cfgVipList
}

func removeAllVipCfg() {
	cfgVipList = []CfgVipItem{}
}

func CfgVipSetRow(rows *sql.Rows) {
	var tVal CfgVipItem
	var err error
	err = rows.Scan(&tVal.Level, &tVal.NeedRunning, &tVal.UpBonus, &tVal.WeekBonus, &tVal.MonthBonus)
	if err != nil {
		helper.InfoLog("TaxVipSetRow,scan err")
		return
	}

	cfgVipList = append(cfgVipList, tVal)
}

func GetVipUpBonus(vipLevel int64) float64 {
	for _, vipItem := range cfgVipList {
		if int64(vipItem.Level) == vipLevel {
			return vipItem.UpBonus
		}
	}

	return 0.00
}

func GetVipWeekBonus(vipLevel int64) float64 {
	for _, vipItem := range cfgVipList {
		if vipItem.Level == vipLevel {
			return vipItem.WeekBonus
		}
	}

	return 0.00
}

func GetVipMonthBonus(vipLevel int64) float64 {
	for _, vipItem := range cfgVipList {
		if vipItem.Level == vipLevel {
			return vipItem.MonthBonus
		}
	}

	return 0.00
}

func GetVipUpLevelNeedRunning(vipLevel int64) float64 {
	var NeedRunning float64 = 0.00
	for _, vipItem := range cfgVipList {
		if vipItem.Level <= vipLevel {
			NeedRunning += vipItem.NeedRunning
		}
	}

	return NeedRunning
}

func GetMaxVipLevel() int64 {
	var MaxVipLevel int64 = 0
	for _, vipItem := range cfgVipList {
		if vipItem.Level >= MaxVipLevel {
			MaxVipLevel = vipItem.Level
		}
	}

	return MaxVipLevel
}
